import Mock from 'mockjs';
const data = [{
    name: 'vivo',
    price: '3999',
    stock: Mock.Random.float(100, 200, 0, 0),
},
{
    name: 'apple',
    price: '7999',
    stock: Mock.Random.float(100, 200, 0, 0),
},
{
    name: 'HUAWEI',
    price: '6999',
    stock: Mock.Random.float(100, 200, 0, 0),
},
{
    name: 'oppo',
    price: '3999',
    stock: Mock.Random.float(100, 200, 0, 0),
},
{
    name: 'honor',
    price: '6499',
    stock: Mock.Random.float(100, 200, 0, 0),
},
{
    name: 'Redmi',
    price: '2999',
    stock: Mock.Random.float(100, 200, 0, 0),
},
{
    name: 'mi',
    price: '4999',
    stock: Mock.Random.float(100, 200, 0, 0),
},
{
    name: 'realme',
    price: '3999',
    stock: Mock.Random.float(100, 200, 0, 0),
},
{
    name: 'iqoo',
    price: '5999',
    stock: Mock.Random.float(100, 200, 0, 0),
},
{
    name: 'ONEPLUS',
    price: '3699',
    stock: Mock.Random.float(100, 200, 0, 0),
},
{
    name: 'SAMSUNG',
    price: '5899',
    stock: Mock.Random.float(100, 200, 0, 0),
},
{
    name: 'meizu',
    price: '3899',
    stock: Mock.Random.float(100, 200, 0, 0),
}]
export default {
    //获取数据的回调
    getGoodsData() {
        return {
            code: 999,
            data,
        }
    },
    //编辑的回调
    editStock(config) {
        let {newStock,name} = JSON.parse(config.body);
        data.forEach((item) => {
            if (item.name == name) {
              item.stock = newStock;
            }
        })
        return {
            code:999,
        }
    }
}